package com.borya.action.mobile;

import com.alibaba.fastjson.JSONObject;
import com.borya.action.BaseAction;
import com.borya.framework.annotation.Action;
import com.borya.framework.annotation.Autowired;
import com.borya.framework.annotation.JsonResult;
import com.borya.framework.annotation.UrlMapping;
import com.borya.framework.core.ServerRequest;
import com.borya.framework.core.ServerResponse;
import com.borya.model.db.User;
import com.borya.service.mobile.MerchantPerfectionService;
import com.borya.statuscode.StatusCode;
import org.apache.log4j.Logger;


/**
 * 商户资料完善
 *
 * @author Administrator
 */
@UrlMapping("/c/perfection/")
@Action
public class MerchantPerfectionAction extends BaseAction {


    private Logger log = Logger.getLogger(getClass());


    @Autowired("merchantPerfectionService")
    private MerchantPerfectionService merchantPerfectionService;

    /**
     * 获取商户信息是否需要完善状态
     *
     * @param request
     * @param response
     * @return
     */
    @UrlMapping("getPerfectionStatus")
    @JsonResult
    public String getPerfectionStatus(ServerRequest request, ServerResponse response) {
        User user = getUser(request);
        String result = merchantPerfectionService.getPerfectionStatus(user);
        log.info("OUT[" + result + "]");
        return result;
    }

    /**
     * 提交商户完善信息
     *
     * @param request
     * @param response
     * @return
     */
    @UrlMapping("addPerfectionData")
    @JsonResult
    public String addPerfectionData(ServerRequest request, ServerResponse response) {
        JSONObject json = getJson(request);
        User user = getUser(request);
        if (json == null) {
            log.warn("请求参数错误");
            return StatusCode.PARAM_ERROR.toJSON();
        }
        log.info("RECV :" + json);
        String result = merchantPerfectionService.addPerfectionData(user, json);
        log.info("OUT :" + result);
        return result;
    }

    /**
     * 获取商户信息完善审核结果
     *
     * @param request
     * @param response
     * @return
     */
    @UrlMapping("getPerfectionResult")
    @JsonResult
    public String getPerfectionResult(ServerRequest request, ServerResponse response) {
        JSONObject json = getJson(request);
        String result = merchantPerfectionService.getPerfectionResult(json);
        log.info("OUT[" + result + "]");
        return result;
    }

    /**
     * 记录活体识别记录
     *
     * @param request
     * @param response
     * @return
     */
    @UrlMapping("addRecord")
    @JsonResult
    public String addRecord(ServerRequest request, ServerResponse response) {
        JSONObject json = getJson(request);
        User user = getUser(request);
        log.info("RECV :" + json + ",USER:" + user);
        String result = merchantPerfectionService.addLivingPreRecord(user, json);
        log.info("OUT[" + result + "]");
        return result;
    }

}
